package com.hobbo.utils;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import com.hobbo.widget.chronograph.ChronographProgress;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        final ChronographProgress chronographProgress = this.findViewById(R.id.chronograph);
        final Button button = this.findViewById(R.id.start);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //0准备 1开始 2暂停
                int state = chronographProgress.getState();
                if (state == 1) {
                    chronographProgress.pause();
                    button.setText("START");
                } else {
                    chronographProgress.start();
                    button.setText("PAUSE");
                }
            }
        });

        this.findViewById(R.id.cancel).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                chronographProgress.reset();
                button.setText("START");
            }
        });
    }
}
